﻿using GalaSoft.MvvmLight;
using mal.Web.Silverlight.MEF.Core;
using mal.Web.Silverlight.MEF.Core.Interfaces;
using mal.Web.Silverlight.MEF.Core.Deployment;

namespace mal.Web.Silverlight.MEF.Shell.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
    /// </para>
    /// <para>
    /// You can also use Blend to data bind with the tool's support.
    /// </para>
    /// <para>
    /// See http://www.galasoft.ch/mvvm/getstarted
    /// </para>
    /// </summary>
    public class MainViewModel : ViewModelBase
    {
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real": Connect to service, etc...
            ////}

            ModulesLoader.Instance.ModulesAvailable += new ModulesAvailableHandler(Instance_ModulesAvailable);
            ModulesLoader.Instance.ModulesLoading += new ModulesLoadingHandler(Instance_ModulesLoading);
        }

        void Instance_ModulesLoading(Module module)
        {
            IsBusy = true;
        }

        void Instance_ModulesAvailable(System.Lazy<System.Windows.Controls.Page, IModuleMetadata>[] modules)
        {
            IsBusy = false;
        }


        private bool isBusy=false;
        public bool IsBusy
        {
            get { return isBusy; }
            set
            {
                if (isBusy != value)
                {
                    isBusy = value;
                    RaisePropertyChanged("IsBusy");
                }
            }
        }
			
			
			

        ////public override void Cleanup()
        ////{
        ////    // Clean own resources if needed

        ////    base.Cleanup();
        ////}
    }
}